import { history } from "umi";
import { objectToStr } from "@/utils";
/**
 * 路由跳转
 * @param pathname
 * @param query
 */
export function navigateTo(pathname: string, query?: Record<string, any>) {
  history.push({
    pathname,
    search: objectToStr(query ?? {}),
  });
}

/**
 * 路由重定向
 * @param pathname
 * @param query
 */
export function redirectTo(pathname: string, query?: Record<string, any>) {
  history.replace({
    pathname,
    search: objectToStr(query ?? {}),
  });
}

/**
 * 路由回转
 * @param step
 */
export function navigateBack(step?: number) {
  history.go(step || -1);
}

/** 路由刷新 */
export function navigateReload() {
  location.reload();
}

export default {
  navigateTo,
  navigateBack,
  navigateReload,
  redirectTo,
};
